var params={};
$(function(){
	var openWindow=window.document;
	var searchHeight=$("#divform").height();
	$("#listUserInfo").height($(openWindow).height()-$(openWindow).height()*0.05-searchHeight-10);
	//动态设置改变操作列宽度
	var fcol=opt.split('</a>');
	var contrlColumn=0;
	if(fcol.length>0){
		contrlColumn=(fcol.length-1)*window.fcolMaxWidth;
	}
	$("#listUserInfo").datagrid({
					url:'/user/getUserInfo',
					title:'用户列表',
					method:'get',
					pagination:true,
					singleSelect:true,
					pageList: window.PageSize,
					view: detailview,
					loadMsg:'加载中......',
					columns:[[
							 {field:'rowid' ,align:'center',title:'操作',fit:true,width:contrlColumn,formatter: function(value, row, index){
								 var re=new RegExp("{param}","g");
								 var ref=opt.replace(re,row.idcard);
								 return ref;
							 }},
					         {field:'idcard',title:'身份证号', align:'center',width:150,sortable:true},
					         {field:'username',title:'姓名',align:'center',width:80},
					         {field:'phone',title:'手机号',align:'center',width:150},
					         {field:'sex',title:'性别',align:'center',width:50,},
					         {field:'birthdate',title:'出生日期',align:'center',width:100},
					         {field:'address',title:'地址',align:'center',width:250,},
					         {field:'sickness',title:'疾病史',align:'center',width:200,},
					         {field:'issmoke',title:'是否抽烟',align:'center',width:80,formatter:function(value,row,index){
					        	 if(value){
					        		 return '是';
					        	 }
					        	 return '否';
					         }},
					         {field:'memberrate',title:'会员等级',align:'center',width:80},
					         {field:'workaddress',title:'工作地址',align:'center',width:250},
					         {field:'lifestyle',title:'生活方式',align:'center',width:80},
					         {field:'race',title:'人种',align:'center',width:80},
					         {field:'bloodtype',title:'血型',align:'center',width:80},
					         {field:'rhfactor',title:'rh因子',align:'center',width:80},
					     ]],
					     detailFormatter:function(index,row){
					            return '<div style="padding:2px"><table id="hraview' + index + '"></table></div>';
			                },
			             onExpandRow:function(index,row){
						    	 var id=row.idcard;
						    	 $("#hraview"+index).datagrid({
						    		 	url:'/user/getUserHra',
						    		 	queryParams:{'idcard':id},
										title:'体检数据',
										method:'get',
										pagination:true,
										pageList: window.subPageSize,
										loadMsg:'加载中......',
//										rowStyler:function(index,row){   
//									        if (row.isflag){   
//									        	return 'background-color:'+window.flagColor;
//									        }   
//									    },
									    columns:[[
													 {field:'did' ,align:'center',title:'操作',width:contrlColumn,formatter: function(value, row, index){
														 var re='<a href="javascripts: void();" onclick="viewHRA(\''+value+'\')" class="a_control">详情</a>&nbsp;';
														 return re;
													 }},
													 {field:'username',title:'用户名称', align:'left',width:100},
													 {field:'huiyuanziliao_jianchariqi',title:'检查日期',width:80,align:'center',sortable:true},
													 {field:'devicename',title:'设备名称', align:'left',width:100,sortable:true},
											         {field:'shopname',title:'设备门店', align:'left',width:100,sortable:true},
											         {field:'modelname',title:'设备型号',align:'left',width:80},
											         {field:'rtc_shengao',title:'身高',align:'left',width:50,},
											         {field:'rtc_tizhong',title:'体重',align:'left',width:50,},
											         {field:'rtc_bmi',title:'bmi指数',align:'left',width:50,},
											         {field:'rtc_gaoya',title:'高压',align:'left',width:50,},
											         {field:'rtc_diya',title:'低压',align:'left',width:50,},
											         {field:'rtc_xinlv',title:'心率',align:'left',width:50,},
											         {field:'rtc_xueyang',title:'血氧',align:'left',width:50,}
//											         {field:'isflag',title:'状态',align:'left',width:80,formatter:function(value,row,index){
//											        	if(value){
//											        		return '已停用';
//											        	}
//											        	else{
//											        		return '已启用';
//											        	}
//											         }}
											     ]],
									    onResize:function(){  
									    	$('#listUserInfo').datagrid('fixDetailRowHeight',index);  
							             },
						                onLoadSuccess:function(){  
						                    setTimeout(function(){  
						                    	$('#listUserInfo').datagrid('fixDetailRowHeight',index);  
						                    },0);  
						                },
						    	 });
						    	 $('#listUserInfo').datagrid('fixDetailRowHeight',index);
						     }
				});
	$("#serbutton").click(function(){
		params.idcard=$("#idcard").val();
		params.username=$("#username").val();
		params.phone=$("#phone").val();
		$("#listUserInfo").datagrid('load',params);
	});
	//绑定回车事件
	$(document).keydown(function(event){ 
		if(event.keyCode==13){
			$("#serbutton").click(); 
		}
	});
	$("#listUserInfo").datagrid({
		toolbar: '#tb'
	});
	//如果操作项为空隐藏操作列
	if(opt==''){
		$("#listUserInfo").datagrid('hideColumn','rowid');
	}
});
/**
 * 重置用户密码
 * @param idcard
 */
function Reset(idcard){
	$.messager.confirm('重置密码','您确定要重置密码吗？',function(data){
		if(data){
			$.ajax({
				type:'get',
				url: '/user/resetPass',
				data:{idcard:idcard},
				success:function(data){
					if(data.code==200){
						$.messager.alert("成功","重置成功",'info');
						$("#listUserInfo").datagrid('load',params);
					}
					else{
						$.messager.alert("失败","重置失败：<br>"+data.msg,'error');
					}
				},
				error:function(data){
					$.messager.alert("失败","重置密码失败：",'error');
				}
			});
		}
	})
}
/**
 * 编辑
 * @param id
 */
function Edit(id){
	window.parent.openDialog("修改用户信息",'/user/editUserInfo','',400,500,'id='+id);
}
/**
 * 打开view页
 */
function viewHRA(id){
	window.parent.opentab('01001','HRA数据详情','/hra/view','id='+id);
}
/**
 * 导出为excel
 */
function exportXls(){
	params.idcard=getVal(params.idcard);
	params.username=getVal(params.username);
	params.phone=getVal(params.phone);
	var url='/user/exportXls?idcard='+params.idcard+'&username='+params.username+'&phone='+
	params.phone;
	window.open(url,'','',false);
}